import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

//1 与下面不同方法 import loginPage from '../views/login'
// 1 {path:'/login',component:loginPage}
const routes = [
    {path:'/',redirect: '/index'},
    // {path:'/index',component:() => import('../views/index')},
    {
        path:'/index',
        component:() => import('../views/index'),
        redirect:'/index/banners',
        meta:{title:'首页'},
        children:[
            {
                path:'banners',
                meta:{title:'轮播图管理'},
                component:() => import('../views/shouye/banner'),
                beforeEnter:(to,from,next) => {
                    ///reject the Navigation
                    console.log('独享守卫')
                    next()
                }
        },
        {path:'category',meta:{title:'分类管理'},component:() => import('../views/shouye/category')},
        {path:'recomend',meta:{title:'为你推荐管理'},component:() => import('../views/shouye/recomend')},
        {path:'pinpai',meta:{title:'品牌管理'},component:() => import('../views/spgl/pinpai')},
        {path:'fenlei',meta:{title:'分类管理'},component:() => import('../views/spgl/fenlei')},
        {path:'danpin',meta:{title:'单品管理'},component:() => import('../views/spgl/danpin')},
        {path:'sp',meta:{title:'商品管理'},component:() => import('../views/spgl/sp')},
        {path:'news', meta:{title:'商品新闻管理'},component:() => import('../views/news')},
        ]
    },
    {path:'/login',component:() => import('../views/login')},
]

// const router = VueRouter.createRouter({
//     routes //'routes:routes'的缩写
// })
const router = new VueRouter({
    routes //'routes:routes'的缩写
})

///全局前置守卫
router.beforeEach((to,from,next) => {
    //...
    ///返回false以取消导航
    // console.log(to,from)
    next()
    // return true
})

export default router